#!/bin/bash

#Optimize system with preload
#
#Authors:
#  Bruno Goncalves Araujo <www.biglinux.com.br>
#
#License: GPLv2 or later
#################################################


#Check permission
if test $(id -u) != 0
then
    echo "Need root permission"
    exit 0
fi


#Options
case "$1" in

    start)
        if [ "$(grep MemTotal: /proc/meminfo | awk '{print $2}')" -gt "400000" ]
        then
	    ln -sf /etc/init.d/preload /etc/rc2.d/S95preload
	else
	    rm -f /etc/rc2.d/S95preload
        fi

	sed -i 's/PRELINKING=.*/PRELINKING=yes/g' /etc/default/prelink


	exit 0
    ;;

    stop)
	    /etc/init.d/preload stop
	exit 0
    ;;

    *)
        echo "Optimize system with preload

start
stop
"

    ;;

esac

